/*
 * redmicro all Copyright (c)
 */

/**
 * Created by seeker910 on 2015/5/25.
 */
Rsd.define('Rsd.Faith.pages.InfoXiaoQuWuYeListPage', {
    extend: 'Rsd.Faith.pages.ListPage',
    requires: [
        'Rsd.controlEx.ComboBoxEx',
        'Rsd.Faith.stores.KaiFaShangStore','Rsd.Faith.stores.WuYeGongSiStore','Rsd.Faith.stores.YeZhuWeiYuanHuiStore'
    ],
    xtype: 'list-xiaoQuWuYe',
    border: false,
    formTitle:'小区（物业）',
    tabTitle: '小区（物业）列表',
    titleField:'MingCheng',
    modelType: 'InfoXiaoQuWuYeBiaoModel',
    newButtons:[{text:'新增小区',handler:'btn_new'}],
    searchColumns:[{name:'MingCheng',text:'小区名称'}],
    formFields: [
        {
            "name": "BianHao",
            "label": {
                "content": "小区编号",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "MingCheng",
            "label": {
                "content": "小区名称",
                "width": 80
            },
            "xtype": "text"
        },

        {
            "name": "JianChengRiQi",
            "label": {
                "content": "建成日期",
                "width": 80
            },
            "xtype": "date",
            "formatString": "yyyy-MM-dd"
        },

        {
            "name": "ZongTaoShu",
            "label": {
                "content": "总套数",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "ZongDongShu",
            "label": {
                "content": "总栋数",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "JianZhuMianJi",
            "label": {
                "content": "建筑面积",
                "width": 80
            },
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "DiZhi",
            "label": {
                "content": "地址",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "WuYeGongSiBianHao",
            "label": {
                "content": "物业公司编号",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "KaiFaShangBianHao",
            "label": {
                "content": "开发商编号",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "YeWeiHuiBianHao",
            "label": {
                "content": "业委会编号",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "SuoShuDiQu",
            "label": {
                "content": "所属地区",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "Remark",
            "label": {
                "content": "备注",
                "width": 80
            },
            "xtype": "text"
        }
    ],
    gridColumns: [
        {
            "text": "序号",
            "xtype": "index",
            "width": 40,
            "sortable": false
        },
        {
            "name": "MingCheng",
            "text": "名称",
            "sortable": false,
            "width": 150,
            "format":"formatMingCheng",
            "nobr": true
        },
        {
            "xtype":'combobox-ex',
            "name": "KaiFaShangBianHao",
            "text": "开发商",
            "sortable": false,
            "width": 150,
            "dataStore":'kaifashang-store',
            "textMember":'MingCheng',
            "nobr": true
        },
        {
            "name": "JianZhuMianJi",
            "text": "建筑面积",
            "sortable": false,
            "xtype": "number",
            "width": 100,
            "precision": 2
        },
        {
            "name": "ZongTaoShu",
            "text": "总套数",
            "sortable": false,
            "width": 50,
            align:'right',
            "nobr": true
        },
        {
            "name": "ZongDongShu",
            "text": "总栋数",
            "sortable": false,
            "width": 50,
            align:'right',
            "nobr": true
        },
        {
            "xtype":'combobox-ex',
            "name": "WuYeGongSiBianHao",
            "text": "物业公司",
            "sortable": false,
            "width": 150,
            "dataStore":'wuyegongsi-store',
            "textMember":'MingCheng',
            "nobr": true
        },
        {
            "xtype":'combobox-ex',
            "name": "YeWeiHuiBianHao",
            "text": "业委会",
            "sortable": false,
            "width": 150,
            "dataStore":'yezhuweiyuanhui-store',
            "textMember":'MingCheng',
            "nobr": true
        },
        {
            "name": "JianChengRiQi",
            "text": "建成日期",
            "sortable": true,
            "sortable": true,
            sortDirection:"desc",
            "xtype": "string",
            "formatString": "yyyy-MM-dd",
            "width": 150
        },
        {
            "name": "SuoShuDiQu",
            "text": "所属地区",
            "sortable": false,
            "width": 150,
            "nobr": true
        },
        {
            "name": "DiZhi",
            "text": "地址",
            "sortable": false,
            "width": 150,
            "nobr": true
        },
        {
            "name": "Remark",
            "text": "备注",
            "sortable": false,
            "width": 150,
            "nobr": true
        }
    ],
    templateCols: [
        {
            name: 'edit',
            text: '操 作',
            nobr:true,
            xtype: 'template',
            format:'templateFormat'
        },{
            name: 'space',
            text: '',
            xtype: 'template',
            width: 5,
            hideable: false,
            sortable: false
        }
    ],
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);
    },
    btn_new:function btn_new()
    {
        var now = new Date();
        var bianHao = (now.getTime()-new Date('1995-01-01').getTime())*10000 + Math.random()*10000;
        this.editItem({BianHao:bianHao});
    },
    formatMingCheng:function(row)
    {
        var me = this;
        var  btn = document.createElement('a');
        btn.href='#';
        btn.innerHTML = '详情';
        $(btn).click (function(){
            Rsd.create('Rsd.Faith.dialogs.InfoXiaoQuWuYeDialog',{data:row}).showDialog();
        } );

        //report.exportexcel
        var s = Rsd.app.getService('report.exportexcel');

        var  btnExport = document.createElement('a');
        btnExport.href=s.server.url + '?xiaoqubianhao='+row['BianHao']+ '&___key='+Rsd.app.token;
        btnExport.innerHTML = '发票导出';
        $(btnExport).click (function(){
            me.showLoading('正在下载...');
            setTimeout(function () {
                me.closeLoading();
            },2000);
        });

        return [Rsd.newLine(),btn,Rsd.blankspan(1),btnExport] ;
    },
    /*
     * */
    templateFormat:function templateFormat(row)
    {
        var me = this;


        var  btnDel = document.createElement('a');
        btnDel.href='#';
        btnDel.innerHTML = '删除';
        $(btnDel).click (function(){me.deleteItem(row);} );

        return [Rsd.blankspan(1),btnDel,Rsd.blankspan(1)] ;
    }
});